//
//  TMGMineFooterView.m
//  TMGold
//
//  Created by Mac on 2017/12/8.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGMineFooterView.h"
@interface TMGMineFooterView()
@property(nonatomic, strong) STLabel                     *myOrderbadgeValueLable;
@property(nonatomic, strong) STLabel                     *youhuibadgeValueLable;
@property(nonatomic, strong) STLabel                     *hongbaobadgeValueLable;
@property(nonatomic, strong) STLabel                     *tijinbadgeValueLable;
@property(nonatomic, strong) STLabel                     *xiaoxibadgeValueLable;
@property(nonatomic, strong) STLabel                     *helpbadgeValueLable;
@end
@implementation TMGMineFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    STButton * bannerImageView = [[STButton alloc] initWithFrame:CGRectMake(0, 10, UIScreenWidth, 61)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:[UIImage imageNamed:@"banner~"]
                                                     image:nil];
    [bannerImageView setClicAction:^(UIButton *sender) {
        if (weakSelf.delegate && [weakSelf.delegate  respondsToSelector:@selector(onSlectedMenuButton:)]) {
            [weakSelf.delegate onSlectedMenuButton:@"图片"];
        }
    }];
    [self addSubview:bannerImageView];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, bannerImageView.bottom + 10, UIScreenWidth, 160)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:whiteView];
    
    //6个按钮
    UIControl * dindan = [self controlWithImageName:@"交易记录01拷贝" title:@"我的订单" tag:10001];
    dindan.st_left = 0;
    [whiteView addSubview:dindan];
    UIControl * youhuiquan = [self controlWithImageName:@"优惠卷" title:@"优惠券" tag:10002];
    youhuiquan.st_left = 0 + UIScreenWidth / 3;
    [whiteView addSubview:youhuiquan];
    UIControl * hongbao = [self controlWithImageName:@"红包" title:@"黄金券" tag:10003];
    hongbao.st_left = 0 + 2 * UIScreenWidth / 3;
    [whiteView addSubview:hongbao];
    UIControl * tijin = [self controlWithImageName:@"提现" title:@"提金" tag:10004];
    tijin.st_left = 0 ;
    tijin.top = dindan.bottom;
    [whiteView addSubview:tijin];
    
    UIControl * xiaoxi = [self controlWithImageName:@"icon消息" title:@"消息" tag:10005];
    xiaoxi.st_left = 0 + UIScreenWidth / 3;
    xiaoxi.top = dindan.bottom;
    [whiteView addSubview:xiaoxi];
    
    UIControl * help = [self controlWithImageName:@"关于我们拷贝" title:@"帮助中心" tag:10006];
    help.st_left = 0 + 2 *UIScreenWidth / 3;
    help.top = dindan.bottom;
    [whiteView addSubview:help];
    
    self.height = whiteView.bottom + 100;
    
}
- (UIControl*)controlWithImageName:(NSString*)imageName title:(NSString*)title tag:(NSInteger)tag{
    UIControl * control = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth / 3, 80)];
    control.backgroundColor = [UIColor whiteColor];
    control.tag = tag;
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 22, 24, 24 )];
    imageView.image = [UIImage imageNamed:imageName];
    imageView.st_centerX = control.st_width / 2;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [control addSubview:imageView];
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, imageView.st_bottom + 10, control.st_width, 13)
                                                     text:title
                                                textColor:TM_firstTextColor
                                                     font:12
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [control addSubview:titleLable];
    [control addTarget:self action:@selector(onSelectedOrderControl:) forControlEvents:UIControlEventTouchUpInside];
    STLabel * badgeValeLable = [[STLabel alloc] initWithFrame:CGRectMake(imageView.right - 6, 0, 20, 14)
                                                         text:@""
                                                    textColor:[UIColor whiteColor]
                                                         font:10
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
    badgeValeLable.bottom = imageView.top + 6;
    badgeValeLable.layer.cornerRadius = 6;
    badgeValeLable.clipsToBounds = YES;
    badgeValeLable.backgroundColor = TM_redColor;
    badgeValeLable.hidden = YES;
    [control addSubview:badgeValeLable];
    
    if (tag == 10001) {
        self.myOrderbadgeValueLable = badgeValeLable;
    }
    if (tag == 10002) {
        self.youhuibadgeValueLable = badgeValeLable;
    }
    if (tag == 10003) {
        self.hongbaobadgeValueLable = badgeValeLable;
    }
    if (tag == 10004) {
        self.tijinbadgeValueLable = badgeValeLable;
    }
    if (tag == 10005) {
        self.xiaoxibadgeValueLable = badgeValeLable;
    }
    if (tag == 10006) {
        self.helpbadgeValueLable = badgeValeLable;
    }
    return control;
}
- (void)onSelectedOrderControl:(UIControl*)control{
    NSString * title;
    if (control.tag == 10001) {
        title = @"我的订单";
    }
    if (control.tag == 10002) {
        title = @"优惠券";
    }
    if (control.tag == 10003) {
        title = @"我的红包";
    }
    if (control.tag == 10004) {
        title = @"提金";
    }
    if (control.tag == 10005) {
        title = @"消息";
    }
    if (control.tag == 10006) {
        title = @"帮助中心";
    }
    if (self.delegate && [self.delegate  respondsToSelector:@selector(onSlectedMenuButton:)]) {
        [self.delegate onSlectedMenuButton:title];
    }
}
@end
